﻿#include "AppInitializer.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKComponents.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKCore/FITKAbstractDataObject.h"
#include "FITK_Component/FITKVAOneXMLIO/FITKVAOneXMLIOInterface.h"
#include <QMessageBox>

bool AppInitializer::init()
{
    //暂时不执行，初始化文件确定后可执行下面的逻辑
    //return true;
    
    AppFrame::FITKComponentInterface* va = FITKAPP->getComponents()->getComponentByName("VAOneXMLIO");
    VAOne::FITKVAOneXMLIOInterface* vaone = dynamic_cast<VAOne::FITKVAOneXMLIOInterface*>(va);
    if (!vaone) return false;

    //获取要存储的数据位置
    Core::FITKAbstractDataObject* model =
        FITKAPP->getGlobalData()->getMeshData<Core::FITKAbstractDataObject>();
    Core::FITKAbstractDataObject* physics =
        FITKAPP->getGlobalData()->getPhysicsData<Core::FITKAbstractDataObject>();
    //传入参数
    vaone->setDataObject("Model", model);
    vaone->setDataObject("Physics", physics);
    //指定文件路径
    QString path = FITKAPP->applicationDirPath() + "\\defaultXML.xml";
    //读取xml文件
    vaone->setFileName(path);
    vaone->runInThread(false);
    vaone->exec(1);
    bool b = vaone->isSuccess();
    //初始化文件读取失败
    if(!b)
    {
        QMessageBox::warning(nullptr, ("warning"), ("Failed to load initialization file, program exits!"));
    }
    return b;
}

